<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Module: Test::Unit::Assertions</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Module</strong></td>
          <td class="class-name-in-header">Test::Unit::Assertions</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../../files/vendor/rails/activesupport/lib/active_support/testing/core_ext/test/unit/assertions_rb.html">
                vendor/rails/activesupport/lib/active_support/testing/core_ext/test/unit/assertions.rb
                </a>
        <br />
            </td>
        </tr>

        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">



   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M002223">assert_difference</a>&nbsp;&nbsp;
      <a href="#M002224">assert_no_difference</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">





      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M002223" class="method-detail">
        <a name="M002223"></a>

        <div class="method-heading">
          <a href="#M002223" class="method-signature">
          <span class="method-name">assert_difference</span><span class="method-args">(expressions, difference = 1, message = nil) {|| ...}</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Test numeric difference between the return value of an expression as a
result of what is evaluated in the yielded block.
</p>
<pre>
  assert_difference 'Article.count' do
    post :create, :article =&gt; {...}
  end
</pre>
<p>
An arbitrary expression is passed in and evaluated.
</p>
<pre>
  assert_difference 'assigns(:article).comments(:reload).size' do
    post :create, :comment =&gt; {...}
  end
</pre>
<p>
An arbitrary positive or negative difference can be specified. The default
is +1.
</p>
<pre>
  assert_difference 'Article.count', -1 do
    post :delete, :id =&gt; ...
  end
</pre>
<p>
An array of expressions can also be passed in and evaluated.
</p>
<pre>
  assert_difference [ 'Article.count', 'Post.count' ], +2 do
    post :create, :article =&gt; {...}
  end
</pre>
<p>
A error message can be specified.
</p>
<pre>
  assert_difference 'Article.count', -1, &quot;An Article should be destroyed&quot; do
    post :delete, :id =&gt; ...
  end
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M002223-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M002223-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/testing/core_ext/test/unit/assertions.rb, line 38</span>
38:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">assert_difference</span>(<span class="ruby-identifier">expressions</span>, <span class="ruby-identifier">difference</span> = <span class="ruby-value">1</span>, <span class="ruby-identifier">message</span> = <span class="ruby-keyword kw">nil</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
39:         <span class="ruby-identifier">expression_evaluations</span> = <span class="ruby-constant">Array</span>(<span class="ruby-identifier">expressions</span>).<span class="ruby-identifier">map</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">expression</span><span class="ruby-operator">|</span>
40:           [<span class="ruby-identifier">expression</span>, <span class="ruby-identifier">lambda</span> <span class="ruby-keyword kw">do</span>
41:             <span class="ruby-identifier">eval</span>(<span class="ruby-identifier">expression</span>, <span class="ruby-identifier">block</span>.<span class="ruby-identifier">__send__</span>(<span class="ruby-identifier">:binding</span>))
42:           <span class="ruby-keyword kw">end</span>]
43:         <span class="ruby-keyword kw">end</span>
44: 
45:         <span class="ruby-identifier">original_values</span> = <span class="ruby-identifier">expression_evaluations</span>.<span class="ruby-identifier">inject</span>([]) { <span class="ruby-operator">|</span><span class="ruby-identifier">memo</span>, <span class="ruby-identifier">expression</span><span class="ruby-operator">|</span> <span class="ruby-identifier">memo</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">expression</span>[<span class="ruby-value">1</span>].<span class="ruby-identifier">call</span> }
46:         <span class="ruby-keyword kw">yield</span>
47:         <span class="ruby-identifier">expression_evaluations</span>.<span class="ruby-identifier">each_with_index</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">expression</span>, <span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
48:           <span class="ruby-identifier">full_message</span> = <span class="ruby-value str">&quot;&quot;</span>
49:           <span class="ruby-identifier">full_message</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;#{message}.\n&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">message</span>
50:           <span class="ruby-identifier">full_message</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;&lt;#{expression[0]}&gt; was the expression that failed&quot;</span>
51:           <span class="ruby-identifier">assert_equal</span> <span class="ruby-identifier">original_values</span>[<span class="ruby-identifier">i</span>] <span class="ruby-operator">+</span> <span class="ruby-identifier">difference</span>, <span class="ruby-identifier">expression</span>[<span class="ruby-value">1</span>].<span class="ruby-identifier">call</span>, <span class="ruby-identifier">full_message</span>
52:         <span class="ruby-keyword kw">end</span>
53:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M002224" class="method-detail">
        <a name="M002224"></a>

        <div class="method-heading">
          <a href="#M002224" class="method-signature">
          <span class="method-name">assert_no_difference</span><span class="method-args">(expressions, message = nil, &amp;block)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Assertion that the numeric result of evaluating an expression is not
changed before and after invoking the passed in block.
</p>
<pre>
  assert_no_difference 'Article.count' do
    post :create, :article =&gt; invalid_attributes
  end
</pre>
<p>
A error message can be specified.
</p>
<pre>
  assert_no_difference 'Article.count', &quot;An Article should not be destroyed&quot; do
    post :create, :article =&gt; invalid_attributes
  end
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M002224-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M002224-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/testing/core_ext/test/unit/assertions.rb, line 67</span>
67:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">assert_no_difference</span>(<span class="ruby-identifier">expressions</span>, <span class="ruby-identifier">message</span> = <span class="ruby-keyword kw">nil</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
68:         <span class="ruby-identifier">assert_difference</span> <span class="ruby-identifier">expressions</span>, <span class="ruby-value">0</span>, <span class="ruby-identifier">message</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>
69:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>